<!--
 * @Author: duan
 * @Description:  double-twelve
 * @Version: 1.0.0
 * @Time: 2020/11/24
-->
<!--膨胀金卡详情-->
<template>
  <div class="packet-details">
    <!--红包卡券详情-->
    <div class="red-packet">
      <img :src="redPacketInfo.topImg" alt="" class="banner-img">
      <div class="goods-info">
        <div class="goods-desc">
          <div class="name">{{ redPacketInfo.redPacketName }}</div>
          <div class="price"><span class="sale-price">¥{{ redPacketInfo.nowAmount }}
          </span> <span style="font-size: 14px;" class="old-price">¥{{ redPacketInfo.amount }}</span></div>
        </div>
      </div>
    </div>

    <!-- 购买数量-->
    <div class="buy-number  blank red-packet-number">
      <div class="content">
        <div class="value">购买份数</div>
        <van-stepper v-model="number" min="1" integer/>
      </div>
    </div>

    <!--膨胀金卡详情-->
    <div class="details blank">
      <div class="content-details">
        <div class="title">商品详情</div>
        <div class="product-desc" v-html="redPacketInfo.details">
        </div>
      </div>
      <div class="title"></div>
    </div>

    <!--底部立即购买-->
    <div class="footer">
      <img @click="contact" :src="imgUrl+'/kefu.png'" alt="" class="kefu">
      <div class="buy" @click="goBuy">立即购买</div>
    </div>

    <!--返回顶部-->
    <BackToTop/>
  </div>
</template>

<script>
import BackToTop from '@/components/BackToTop'
import { Toast } from 'vant'

export default {
  components: { BackToTop },
  data () {
    return {
      // 红包描述和详情
      redPacketInfo: {},
      // 购买数量
      number: 1
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created () {
    this.redPacketShow() // 获取红包详情
  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted () {
    // 此处true需要加上，不加滚动事件可能绑定不成功
    window.addEventListener('scroll', this.handleScroll)
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll)
  },
  // 方法
  methods: {
    // 1丶红包膨胀金卡详情===============================================
    // 红包膨胀金卡展示
    redPacketShow () {
      this.$HttpGet(this.$api.redPacketShow).then((res) => {
        if (res.code === '000') {
          this.redPacketInfo = res.content
        }
      })
    },
    // 2丶购买下单按钮=================================================
    goBuy () {
      if (!this.redPacketInfo.redPacketNo) {
        return Toast('红包不存在')
      }
      this.$eventBus.$emit('changeAddress', '')
      this.$router.push({
        path: '/confirm',
        query: {
          activityProductNo: this.redPacketInfo.redPacketNo,
          number: this.number,
          coupon: '1'
        }
      })
      window._czc.push(['_trackEvent', '膨胀金详情', '膨胀金下单购买', this.redPacketInfo.redPacketNo])
    },
    // 联系客服
    contact () {
      this.$router.push({
        path: '/feedback'
      })
    }
  }
}
</script>
<style scoped lang='scss'>

.packet-details {
  position: relative;
  width: 100%;
  min-height: 100%;
  padding-bottom: 100px;
  overflow-x: hidden;
  background-color: #F4F5F7;

  /*商品详情*/
  .red-packet {
    position: relative;
    width: 100%;
    height: 487px;
    z-index: 9;

    .banner-img {
      position: absolute;
      left: 0;
      top: 0;
      background-color: #F4F5F7;
      width: 100%;
      height: 100%;
      z-index: -9;
    }

    .goods-info {
      position: absolute;
      bottom: -70px;
      left: 0;
      width: 100%;
      box-sizing: border-box;
      padding: 0 14px;
      z-index: 99;
    }

    .goods-desc {
      display: flex;
      justify-content: space-between;
      flex-direction: column;
      width: 100%;
      height: 100%;
      padding: 32px 23px 22px 23px;
      box-sizing: border-box;
      border-radius: 14px;
      background-color: #ffffff;

      .name {
        align-self: start;
        font-size: 36px;
        font-family: PingFang, PingFang-SC;
        font-weight: 600;
        color: #000000;
        text-align: left;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }

      .price {
        align-self: flex-end;

        .sale-price {
          font-size: 40px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          color: #d93939;
        }

        .old-price {
          margin-left: 15px;
          font-family: PingFangSC, PingFangSC-Light;
          font-weight: 300;
          color: #989898;
          text-decoration: line-through;
        }
      }

      .start {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 25px;
        font-family: PingFang, PingFang-SC;
        color: #000000;

        .van-count-down {
          margin-left: 5px;
          font-size: 12px;
          color: #d93939;
        }
      }
    }
  }

  /*购买数量*/
  .blank {
    width: 100%;
    box-sizing: border-box;
    padding: 0 14px;
    margin-top: 26px;

    &.red-packet-number {
      margin-top: 90px;
    }

    .content {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #ffffff;
      border-radius: 14px;
      box-sizing: border-box;
      padding: 30px 25px;

      .value {
        font-size: 29px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        color: #3e3e3e;
        letter-spacing: 1px;
      }
    }

    &.details {
      margin-top: 20px;

      .content-details {
        display: flex;
        justify-content: start;
        align-items: start;
        flex-direction: column;
        width: 100%;
        min-height: 400px;
        background-color: #ffffff;
        border-radius: 14px;
        box-sizing: border-box;
        padding: 30px 0;
        margin-bottom: 100px;
        padding-bottom: 50px;
        box-sizing: border-box;
        overflow: hidden;

        .title {
          position: relative;
          margin-left: 40px;
          margin-top: 19px;
          font-size: 29px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          color: #3e3e3e;
          text-align: left;
          line-height: 41px;
          letter-spacing: 1px;

          &::after {
            content: '';
            position: absolute;
            left: -20px;
            top: 10px;
            display: block;
            width: 5px;
            height: 23px;
            background: #000000;
          }
        }

        .product-desc {
          max-width: 100%;
          overflow: hidden;
        }
      }

    }
  }

  /*底部立即抢购*/
  /*底部立即抢购*/
  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 120px;
    z-index: 99;

    .kefu {
      position: absolute;
      left: 100px;
      top: 20px;
      width: 50px;
      height: 50px;
      z-index: 999;
    }

    .buy {
      width: 690px;
      height: 90px;
      margin: 0 auto;
      background: linear-gradient(84deg, #d1203c 1%, #b0071e 69%);
      border-radius: 45px;
      font-size: 36px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      color: #ffffff;
      line-height: 90px;
    }
  }

  /*返回头部*/
  .go-top {
    position: fixed;
    right: 30px;
    bottom: 150px;
    width: 62px;
    height: 62px;
    z-index: 99;
  }

}

</style>
